using UnityEngine;

public class Demo : MonoBehaviour
{
	public GUISkin skin;

	private AudioClip clip;

	public GUIStyle rowSelectedStyle;

	public Vector2 scrollPosition;

	public float numRows;

	public Vector2 rowSize;

	public Vector2 windowMargin;

	public Vector2 listMargin;

	private Rect windowRect;

	private float originalWidth = 640f;

	private float originalHeight = 360f;

	private Vector2 scale;

	public int tune = 20000;

	public float fStopThreshold = 1f;

	public float coef = 850f;

	public float smoothcoef = 0.05f;

	private float fResistanceFactor = 0.9f;

	private bool bTranslating;

	private Vector3 v3StartPos;

	private Vector3 v3LastPos;

	private Vector3 v3Delta;

	private float fStartTime;

	private float scrollPositionL;

	private float scrh;

	private bool scrollable = true;

	private void Start()
	{
		scrh = Screen.height;
		AndroidPurchases.Load();
		if ((float)Screen.height > 800f)
		{
			numRows = (float)tune / ((float)Screen.height + 32f);
		}
		else
		{
			numRows = (float)tune / ((float)Screen.height + 380f);
		}
		if ((float)Screen.width > 640f)
		{
			scale.x = (float)Screen.width / originalWidth;
			scale.y = (float)Screen.height / originalHeight;
		}
		else
		{
			scale.x = 1f;
			scale.y = 1f;
		}
		if ((float)Screen.width > 1020f)
		{
			scale.x = 1024f / originalWidth;
			scale.y = 600f / originalHeight;
		}
	}

	private void OnDestroy()
	{
		AndroidPurchases.StopInAppBilling();
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
		{
			UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu2");
		}
		if (!scrollable)
		{
			return;
		}
		if (Input.GetMouseButtonDown(0))
		{
			bTranslating = false;
			v3StartPos = UnityEngine.Input.GetTouch(0).position;
			v3LastPos = v3StartPos;
			fStartTime = Time.time;
		}
		if (Input.GetMouseButtonUp(0))
		{
			v3Delta = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = v3Delta;
				fStartTime = Time.time;
			}
			v3Delta = (v3Delta - v3StartPos) / (Time.time - fStartTime);
			bTranslating = true;
			if (Mathf.Abs(v3Delta.y) < 300f)
			{
				v3Delta.y = 0f;
			}
		}
		if (Input.GetMouseButton(0))
		{
			Vector3 a = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = UnityEngine.Input.GetTouch(0).position;
				v3LastPos = v3StartPos;
				fStartTime = Time.time;
			}
			Vector2 vector = a - v3LastPos;
			vector.x = 0f;
			vector.y /= scrh;
			scrollPosition.y += vector.y * coef;
			scrollPositionL = scrollPosition.y;
			v3LastPos = a;
		}
		if (bTranslating && v3Delta.magnitude > 10f)
		{
			scrollPositionL += v3Delta.y * smoothcoef;
			v3Delta *= fResistanceFactor;
			if (v3Delta.magnitude < fStopThreshold)
			{
				bTranslating = false;
			}
		}
		if (!Input.GetMouseButton(0))
		{
			scrollPosition.y = Mathf.Lerp(scrollPosition.y, scrollPositionL, Time.deltaTime * 8f);
		}
	}

	private void OnGUI()
	{
		GUI.skin = skin;
		windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
		GUI.Window(0, windowRect, DoWindow, "In-App Purchase Store");
	}

	private void DoWindow(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		scrollPosition = GUI.BeginScrollView(new Rect(listMargin.x, listMargin.y, vector.x, vector.y), viewRect: new Rect(0f, 0f, rowSize.x, numRows * rowSize.y), scrollPosition: scrollPosition, alwaysShowHorizontal: false, alwaysShowVertical: false);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUILayout.Label("Tap 'spintops.full' button to open Google Play pop-up to purchase the 'Ad Free + Extra Content + Support Dev'-packet");
		GUI.contentColor = Color.white;
		string[] purchasableItems = AndroidPurchases.PurchasableItems;
		foreach (string text in purchasableItems)
		{
			GUI.enabled = !AndroidPurchases.HasPurchased(text);
			if (GUILayout.Button(text, GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
			{
				AndroidPurchases.PurchaseItem(text);
				foreach (PurchaseInfo purchaseInfo in AndroidPurchases.Instance.PurchaseInfos)
				{
					if (purchaseInfo.productId == "spintops.full")
					{
						PlayerPrefs.SetInt("tmp", 7);
						MonoBehaviour.print("bought");
					}
				}
			}
			GUI.enabled = true;
		}
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUILayout.Label("What you'll get currently with the purchase.");
		GUI.contentColor = Color.white;
		GUILayout.Label("* Remove all ads");
		GUILayout.Label("* Unlock exclusive colorful new stadium: 'Marching Cubes'");
		GUILayout.Label("* Supporter badge in Main Menu");
		GUILayout.Label("* More exclusive content is coming with updates...");
		GUILayout.Label(string.Empty);
		GUILayout.Label("Tap 'Restore Purchases' if you have bought In-App Purchase but haven't got it for some reason, or you have deleted application data and the purchase hasn't been restored");
		if (GUILayout.Button("Restore Purchases", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AndroidPurchases.RestoreTransactions();
		}
		GUILayout.Label("Log Info:");
		GUILayout.Label(AndroidPurchases.LogInfo());
		if (GUILayout.Button("Back", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu2");
		}
		GUI.EndScrollView();
	}

	private void PurchaseItem(string productID)
	{
		UnityEngine.Debug.Log("ANDROID - PurchaseItem");
		AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.platoevolved.inappbilling.UnityAndroidInterface");
		androidJavaClass.CallStatic("PurchaseItem", productID);
	}

	private void BeginPage(float width, float height)
	{
		GUILayout.BeginArea(new Rect(((float)Screen.width - width) / 2f, ((float)Screen.height - height) / 2f, width, height));
	}

	private void EndPage()
	{
		GUILayout.EndArea();
	}
}
